/**
 * ZHU framework. Copyright 2012-, all rights reserved.
 *
 * $Id: MenuLifecycle.java 47 2012-09-20 06:31:35Z zhuxiaopeng $
 * $Revision: 47 $
 * $Date: 2012-09-20 14:31:35 +0800 (四, 2012-09-20) $
 * $Author: zhuxiaopeng $
 */
package daily.entity;

import java.util.*;

import javax.persistence.*;

import zhu.framework.entity.lifecycle.*;

/**
 * <p>
 * </p>
 * 
 * @author $Author: zhuxiaopeng $
 * @version $Revision: 47 $ - $Date: 2012-09-20 14:31:35 +0800 (四, 2012-09-20) $
 */
public class MenuLifecycle extends AbstractLifecycle<Menu> {

	public MenuLifecycle(final LifecycleContext lifecycleContext) {
		super(lifecycleContext);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see zhu.framework.entity.lifecycle.Lifecycle#getEntityType()
	 */
	@Override
	public Class<Menu> getEntityType() {
		return Menu.class;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see zhu.framework.entity.lifecycle.Lifecycle#newInstance()
	 */
	@Override
	public Menu newInstance() {
		return new Menu();
	}

	public List<Menu> findAllUsed() {
		final StringBuilder buf = new StringBuilder();
		buf.append(" select o from Menu o ");
		buf.append(" where o.used = true");
		buf.append(" order by o.index ");
		final Query query = getEntityManager().createQuery(buf.toString());
		return getQueryResultList(query);
	}

	public List<Menu> findByStaffGroup(final StaffType staffType) {
		final StringBuilder buf = new StringBuilder();
		buf.append(" select o from Menu o ");
		buf.append(" where o.used = true");
		buf.append(" and o.staffType = :theStaffType");
		buf.append(" order by o.index ");
		final Query query = getEntityManager().createQuery(buf.toString());
		query.setParameter("theStaffType", staffType);
		return getQueryResultList(query);
	}
}
